#define GPFSEL1		0x20200004U
#define GPCLR0		0x20200028U
#define GPSET0		0x2020001CU


static unsigned int ledStatus = 0U;


void TurnLedOn(void)
{
	// On allume la led
	unsigned int *gpclr0_ptr = ((unsigned int*)GPCLR0);
	*gpclr0_ptr = *gpclr0_ptr | 0x10000U;
	ledStatus++;
}

void TurnLedOff(void)
{
	// On éteint la led
	unsigned int *gpclr0_ptr = ((unsigned int*)GPSET0);
	*gpclr0_ptr = *gpclr0_ptr | 0x10000U;
	ledStatus++;
}

void SwitchLed(void)
{
	if ((ledStatus & 1U) == 0U)
	{
		TurnLedOff();
	}
	else
	{
		TurnLedOn();
	}
}

unsigned int GetLedStatus(void)
{
	return ledStatus;
}

void InitLed(void)
{
	// On active la fonction du 1 du pin 16 du GPIO
	unsigned int *gpfsel1_ptr = ((unsigned int*)GPFSEL1);
	*gpfsel1_ptr = *gpfsel1_ptr | 0x40000U;
	TurnLedOff();
}
